package br.com.obardavez.base.dao.impl;

import java.lang.annotation.Annotation;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceUnit;

import br.com.obardavez.base.dao.EntityManagerFinder;
import br.com.obardavez.util.Util;

import com.google.inject.Inject;

public class EntityManagerFinderImpl implements EntityManagerFinder {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Inject
	@PersistenceUnit
	protected EntityManager entityManager;



	@Inject
	private Util util;

	@Override
	public EntityManager getEntityManager(Class<? extends Annotation> annotation) {
		EntityManager entityManager = this.entityManager;
		if (annotation != null) {
			entityManager = (EntityManager) util.getBeanUtil()
					.getPropertyValue(this, annotation);
		}
		return entityManager;
	}

}
